package com.mediocre.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

//@EnableFeignClients
//@EnableDiscoveryClient
@SpringBootApplication
public class SpringcloudGatewayApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        // new SpringApplicationBuilder(SpringcloudGatewayApplication.class).web(true).run(args);
        SpringApplication.run(SpringcloudGatewayApplication.class, args);
    }

    /*@Bean
    public MyTokenFilter tokenFilter() {
        return new MyTokenFilter();
    }*/

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
// Do any additional configuration here return builder.build();
        return builder.build();
    }

    @Bean
    public ServletContextInitializer initializer() {
        return new ServletContextInitializer() {
            @Override
            public void onStartup(ServletContext servletContext) throws ServletException {
                servletContext.setAttribute("jsVer", "1.0");
            }
        };
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(SpringcloudGatewayApplication.class);
    }
}
